package com.his.server.interceptor;

import org.apache.commons.lang.xwork.StringUtils;

import com.his.server.consts.ServerConsts;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import com.his.server.logicdata.UserInfoLogicData;
import com.his.server.utils.main.BaseContext;

public class LoginInterceptor extends AbstractInterceptor {
	
	public String intercept(ActionInvocation invocation) throws Exception {  
    
		String username = null;
		String password = null;
		boolean validflag = true;
		
        UserInfoLogicData userInfoLogicData = 
        		(UserInfoLogicData) BaseContext.getAtribute(ServerConsts.SK_USERINFOLOGICDATA);  

        if (userInfoLogicData != null) {
        	username = userInfoLogicData.getName();
        	password = userInfoLogicData.getPassword();
        }
        
        if(StringUtils.isEmpty(username) || 
        		StringUtils.isEmpty(password)){  
        	validflag = false; 
        }
      
        if (validflag) {
        	
        	return invocation.invoke(); 
        } else {
        	
        	userInfoLogicData.setLoginflag(ServerConsts.LOGINFLAG_2);
        	BaseContext.setAtribute(ServerConsts.SK_USERINFOLOGICDATA, userInfoLogicData);
        	
        	return ServerConsts.REQUEST_LOGIN_FAILURE;
        }
        
    } 
	
}